{{define "/user/login.shtml"}}
<!DOCTYPE html>
<html>
<head>
    {{template "/chat/head.shtml"}}
</head>
<body>

<header class="mui-bar mui-bar-nav">
    <h1 class="mui-title">登录</h1>
</header>
<div class="mui-content" id="pageapp">
    <form id='login-form' class="mui-input-group">
        <div class="mui-input-row">
            <label>账号</label>
            <input v-model="user.mobile" placeholder="请输入手机号" type="text" class="mui-input-clear mui-input" >
        </div>
        <div class="mui-input-row">
            <label>密码</label>
            <input v-model="user.passwd" placeholder="请输入密码"  type="password" class="mui-input-clear mui-input" >
        </div>
    </form>
    <div class="mui-content-padded">
        <button @click="login"  type="button"  class="mui-btn mui-btn-block mui-btn-primary">登录</button>
        <div class="link-area"><a id='reg' href="register.shtml">注册账号</a> <span class="spliter">|</span> <a  id='forgetPassword'>忘记密码</a>
        </div>
    </div>
    <div class="mui-content-padded oauth-area">
    </div>
</div>
</body>
</html>
<script>
    var app = new Vue({
        el:"#pageapp",
        data:function(){
            return {
                user:{
                    mobile:"",
                    passwd:""
                }
            }
        },
        methods:{
            login:function(){
                //检测手机号是否正确
                var regMobile = /(\d){11}/
                if (this.user.mobile == "" || !regMobile.test(this.user.mobile)){
                    mui.toast("手机号不正确!")
                    return false
                }
                //检测密码是否为空
                if (this.user.passwd == "") {
                    mui.toast("密码不能为空!")
                    return false
                }
                //网络请求
                //封装了promis
                util.post("/user/login",this.user).then(res=>{
                    if(res.code != 0){
                        mui.toast(res.msg)
                    }else{
                        var url = "/chat/index.shtml?id=" + res.data.id + "&token=" + res.data.token;
                        //alert有确定按钮；toast没有确定按钮
                        //mui.alert(url)
                        mui.toast("登录成功,即将跳转")
                        userInfo(res.data);
                        userId(res.data.id)
                        location.href = url;
                    }
                })
            },
        }
    })
</script>
{{end}}